package cn.simon.controller;

import cn.simon.model.Users;
import cn.simon.service.UsersService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/users")
@Log
public class UsersController {

    @Autowired
    private UsersService usersService;

    /**
     *查看用户信息
     */
    @GetMapping("/getAllUsers")
    public String users(Model model){
        List<Users> list=usersService.getAllUsers();
        log.info(list.toString());
        model.addAttribute("list",list);
        return "userList";
    }

    @GetMapping("/findById")
    public Users findById(Integer id){
        return usersService.findById(id);
    }

    /**
     * 冻结用户
     */
    @GetMapping("/freezeUser")
    public  String freezeUser(Integer id){
        usersService.freezeUser(id);
        return "redirect:/users/getAllUsers";
    }

    /**
     * 激活用户
     */
    @GetMapping("/unFreezeUser")
    public  String unFreezeUser(Integer id){
        usersService.unFreezeUser(id);
        return "redirect:/users/getAllUsers";
    }
}
